<template>
	<view>
		<block v-if="list.length == 0">
			<view :style="{ height: systemInfo.windowHeight + 'px'}">
				<u-empty src="https://gxmanager.oss-cn-shenzhen.aliyuncs.com/xfqczbgl_static/no-data.png" icon-size="300" text="暂无院区数据，赶紧添加一条吧！"></u-empty>
			</view>
		</block>
		<block v-else>
			<scroll-view scroll-y>
				<view class="base-list">
					<view class="base-item" v-for="(item,index) in list" :key="index">
						<view class="base-info row">
							<view class="base-content u-flex-col u-row-between">
								<view>
									<view class="notic-title">所属院区：{{ item.deptName }}</view>
									<view class="notic-title">年目标业绩：{{ item.nmb }}</view>
									<view class="notic-title">月目标业绩：{{ item.ymb }}</view>
									<!-- <view class="notic-title">院区地址：{{ item.address }}</view> -->
									<!-- <view class="notic-desc text-gray u-flex">共有1个院区管理员、10个业务员账号</view> -->
									<view class="notic-desc text-gray u-flex">共有{{ item.sort }}个账号</view>
								</view>
							</view>
						</view>
						<view class="base-handle">
							<u-button class="btn" type="primary" @click="navTo('courtyardForm', { type: 1, id: item.deptId })">编辑</u-button>
							<u-button class="btn" type="error" @click="delCourtyard(item.deptId)" v-if="item.sort == 0">删除</u-button>
							<u-button class="btn" type="success" @click="navTo('account', { deptId: item.deptId, deptIndex: index })">账号管理</u-button>
						</view>
					</view>
				</view>
			</scroll-view>
			<u-loadmore :status="status" />
		</block>
		<u-gap height="200" v-if="list.length != 0"></u-gap>
		<u-button class="base-add" type="primary" @click="navTo('courtyardForm', { type: 0 })">
			<u-icon class="base-add-icon" name="plus" color="#fff" size="28"></u-icon>新增院区
		</u-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				status: 'loadmore',
				list: [
					// {
					// title: '浙江院区',
					// content: '张三 - 13888888888',
					// },
				],
				page: 1,
				limit: 10,
				total: 0
			};
		},
		computed: {
			userInfo() {
				if (Object.keys(this.$store.state.userInfo).length != 0) {
					return this.$store.state.userInfo
				} else if (Object.keys(uni.getStorageSync('userInfo')).length != 0) {
					return uni.getStorageSync('userInfo')
				} else {
					return {
						avatar: "",
						createTime: "",
						dataRoleId: "",
						dept: "",
						deptId: "",
						deptName: "",
						email: "",
						enable: "",
						nickName: "",
						phone: "",
						roleIds: "",
						sex: "",
						userId: "",
						userName: "",
					}
				}
			}
		},
		onReachBottom() {
			// 判断数据是否全部加载完毕，true则停止请求接口，修改loadingmore状态
			if (this.list.length >= this.total) {
				this.status = 'nomore'
				return;
			}
			this.status = 'loading';
			this.page += 1;
			this.getListData(true); //调用数据
		},
		methods: {
			getListData(isPush = false) {
				this.$api.deptList({
					current: this.page,
					size: this.limit
				}).then(res => {
					let data = res.data
					this.total = data.total
					if (!isPush) {
						this.list = []
					}
					if (this.total < this.limit) { // 不足10条数据
						this.status = 'nomore'
					}
					for (let i of data.records) {
						this.list.push(i)
					}
				})
			},
			navTo(path, params) {
				this.$Router.push({ name: path, params })
			},
			reset() {
				this.status = 'loading';
				this.page = 1
				this.list = []
				this.getListData()
			},
			delCourtyard(id) {
				uni.showModal({
					content: '确定要删除该院区吗？',
					success: (res) => {
						if (res.confirm) {
							this.$api.deptDel({id}).then(res => {
								this.getListData()
								uni.showToast({
									title: '删除成功！'
								})
							})
						}
					}
				})
			}
		},
		onLoad() {
			this.getListData()
		}
	}
</script>

<style>
	page {
		background-color: #F7F7F7;
	}
	.notic-title{
		font-size: 28rpx;
	}
	.notic-desc{
		margin-top: 10rpx;
		font-size: 24rpx;
		justify-content: space-between;
		align-items: center;
	}
	
</style>
